package org.lqk.file.transfer.client.processor;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.lqk.file.transfer.client.framework.AbstractFileResponseProcessor;
import org.lqk.file.transfer.netty.RequestFuture;
import org.lqk.file.transfer.protocol.FileSegmentResponse;
import org.lqk.file.transfer.protocol.RemotingCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

import io.netty.channel.ChannelHandlerContext;

/**
 * 接到一个segment响应，如果成功，就检查是否所有的segment都发送成功了，如果都成功了，返回true，将控制权交给用户。如果失败，检查还没发的（
 * 要加锁）发一个
 * 
 * @author bert
 *
 */
public class FileSegmentResponseProcessor extends AbstractFileResponseProcessor {
	private static Logger log = LoggerFactory.getLogger(FileSegmentResponseProcessor.class);

	public FileSegmentResponseProcessor(ConcurrentHashMap<Integer, RequestFuture> requestTable, int cmdCode) {
		super(requestTable, cmdCode);
	}

	@Override
	public boolean process(ChannelHandlerContext ctx, RemotingCommand command) throws IOException {
		FileSegmentResponse segmentResponse = (FileSegmentResponse) command.getBody();
		// 如果有文件失敗，或文件成功，結束
		if (!segmentResponse.isBlockState() || segmentResponse.isFileState()) {
			return true;
		}
		//
		return false;

	}
}
